<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>this_bug2</title>
</head>
<body>

</body>
<script>
    class Log {
        printName(name = 'hello') {
            this.print(`hello  ${name}`);
        }

        print(text) {
            console.log(text);
        }
    }

    function selfish(target) {
        const cache = new WeakMap();
        const handler = {
            get (target, key) {
                const value = Reflect.get(target, key);
                if (typeof value !== 'function') {
                    return value;
                }
                if (!cache.has(value)) {
                    cache.set(value, value.bind(target));
                }
                return cache.get(value);
            }
        };
        const proxy = new Proxy(target, handler);
        return proxy;
    }

    const logger = selfish(new Log());
    logger.printName();
</script>
</html>